//
//  OMMallRecommendTableCell.m
//  OMENGO
//
//  Created by 梁尚嘉 on 2016/12/9.
//  Copyright © 2016年 Kamfat. All rights reserved.
//

#import "OMMallRecommendTableCell.h"
@interface OMMallRecommendTableCell ()
@property (nonatomic, strong) UIImageView *leftImageView;
@property (nonatomic, strong) UIImageView *rightTopImageView;
@property (nonatomic, strong) UIImageView *rightBottomImageView;

@property (nonatomic, strong) NSArray *imageViews;

@property (nonatomic, strong) NSArray <OMMallRecommendItem *>*items;
@end
@implementation OMMallRecommendItem
@end
@implementation OMMallRecommendTableCell

- (void)configure
{
    [super configure];
    self.contentView.backgroundColor = SM_backGroundColor;
    [self.contentView addSubview:self.leftImageView];
    [self.contentView addSubview:self.rightTopImageView];
    [self.contentView addSubview:self.rightBottomImageView];

    _imageViews = @[self.leftImageView,self.rightTopImageView,self.rightBottomImageView];

    for (UIImageView *imageView in _imageViews) {
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(didTapImageView:)];
        imageView.userInteractionEnabled = YES;
        [imageView addGestureRecognizer:tap];
    }

    [self.leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.top.equalTo(@0);
        make.right.equalTo(self.contentView.mas_centerX);
    }];

    [self.rightTopImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.equalTo(@0);
        make.bottom.equalTo(self.contentView.mas_centerY);
        make.left.equalTo(self.leftImageView.mas_right).offset(1);
    }];

    [self.rightBottomImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.rightTopImageView.mas_bottom).offset(1);
        make.left.equalTo(self.rightTopImageView);
        make.right.bottom.equalTo(@0);
    }];
}

- (void)configureCellWithObj:(NSArray <OMMallRecommendItem*>*)items
{
    _items = items;
    [self.leftImageView kt_imageWithURLStr:items[0].image placeHolder:nil withSize:CGSizeZero];
    [self.rightTopImageView kt_imageWithURLStr:items[1].image placeHolder:nil withSize:CGSizeZero];
    [self.rightBottomImageView kt_imageWithURLStr:items[2].image placeHolder:nil withSize:CGSizeZero];
}

- (void)didTapImageView:(UITapGestureRecognizer *)tapG
{
    NSUInteger index = [self.imageViews indexOfObject:tapG.view];
    OMMallRecommendItem *item = self.items[index];
    NSDictionary *propertys = @{@"title":item.name,@"item":item};
    if (item.type == 1) {//服务类商品
        NaviPush(@"OMServiceViewController", propertys);
    }else if (item.type == 2) { //居家商品
        NaviPush(@"OMConsumerGoodsViewController", propertys);
    }else if (item.type == 4) { //全部分类
        NaviPush(@"OMMallAllCategoryViewController", propertys);
    }
}


- (UIImageView *)leftImageView
{
    if (!_leftImageView) {
        _leftImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"02-dianzhang"]];
        _leftImageView.backgroundColor = SM_placeholdColor;
    }
    return _leftImageView;
}

- (UIImageView *)rightTopImageView
{
    if (!_rightTopImageView) {
        _rightTopImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"02-fangbianmian"]];
        _rightTopImageView.backgroundColor = SM_placeholdColor;
    }
    return _rightTopImageView;
}

- (UIImageView *)rightBottomImageView
{
    if (!_rightBottomImageView) {
        _rightBottomImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"02-jingxuan"]];
        _rightBottomImageView.backgroundColor = SM_placeholdColor;
    }
    return _rightBottomImageView;
}

+ (CGFloat)cellHeight
{
    return (SM_SCREEN_WIDTH/2.f)*342/362;
}

@end
